All files / src/components/admin/contentManagement stream.ts

0% Statements 0/36
0% Branches 0/33
0% Functions 0/3
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
export type StreamKind = 'HLS' | 'DASH' | 'MP4' | 'OTHER';
 
/** Check the URL path AND query-param values for a manifest extension. */
const hasExt = (url: string, ext: string): boolean => {
  const re = new RegExp(`\\.${ext}([?&#]|$)`, 'i');
  if (re.test(url)) return true;
  try {
    const u = new URL(url, typeof window !== 'undefined' ? window.location.origin : undefined);
    for (const val of u.searchParams.values()) {
      if (re.test(val)) return true;
    }
  } catch { /* ignore */ }
  return false;
};
 
export const inferVideoType = (url: string): string => {
  if (hasExt(url, 'm3u8')) return 'application/x-mpegURL';
  if (hasExt(url, 'mpd')) return 'application/dash+xml';
  const cleaned = url.split('?')[0]?.toLowerCase() ?? url.toLowerCase();
  if (cleaned.endsWith('.webm')) return 'video/webm';
  if (cleaned.endsWith('.ogv') || cleaned.endsWith('.ogg')) return 'video/ogg';
  if (cleaned.endsWith('.mov')) return 'video/quicktime';
  return 'video/mp4';
};
 
export const streamKind = (url?: string | null): StreamKind => {
  if (!url) return 'OTHER';
  if (hasExt(url, 'm3u8')) return 'HLS';
  if (hasExt(url, 'mpd')) return 'DASH';
  const cleaned = url.split('?')[0]?.toLowerCase() ?? url.toLowerCase();
  if (cleaned.endsWith('.mp4') || cleaned.endsWith('.mov') || cleaned.endsWith('.webm')) return 'MP4';
  return 'OTHER';
};